/**
 *
 */
import OpenApi;
import OpenApi.OpenApiUtil;

extends OpenApi;


init(config: OpenApiUtil.Config){
  super(config);
  @endpointRule = '';
  
  checkConfig(config);
  @endpoint = getEndpoint('aipodcast', @regionId, @endpointRule, @network, @suffix, @endpointMap, @endpoint);
}

function getEndpoint(productId: string, regionId: string, endpointRule: string, network: string, suffix: string, endpointMap: map[string]string, endpoint: string) throws: string{
  if (!$isNull(endpoint)) {
    return endpoint;
  }
  
  if (!$isNull(endpointMap) && !$isNull(endpointMap[regionId])) {
    return endpointMap[regionId];
  }
  return OpenApiUtil.getEndpointRules(productId, regionId, endpointRule, network, suffix);
}

model PodcastTaskResultQueryRequest {
  taskId?: string(name='taskId', description='This parameter is required.', example='63c4e0eaab3b4c0db208ecafa990e8d1'),
  workspaceId?: string(name='workspaceId', description='This parameter is required.', example='llm-ep8ba0dr6seiddri'),
}

model PodcastTaskResultQueryResponseBody = {
  code?: string(name='code', example='"success"'),
  data?: {
    resultUrl?: any(name='resultUrl', example='{
            "audio": "http://note-ai-file.oss-cn-beijing.aliyuncs.com/202503241702148295/audio.mp3?OSSAccessKeyId=LTAI5tPLWJfJHNkZbfnQv245&Expires=1742810788&Signature=b5p83nh443Gr7foqdvgrI4%2FKZVM%3D",
            "script": "http://note-ai-file.oss-cn-beijing.aliyuncs.com/202503241702148295/script.txt?OSSAccessKeyId=LTAI5tPLWJfJHNkZbfnQv245&Expires=1742810622&Signature=TBBdikHzOWW3YqDw3sNMTXiMo6A%3D"
}'),
    script?: string(name='script'),
    taskId?: string(name='taskId', example='63c4e0eaab3b4c0db208ecafa990e8d1'),
    taskStatus?: string(name='taskStatus', example='SUCCEEDED'),
  }(name='data'),
  httpStatusCode?: string(name='httpStatusCode', example='200'),
  message?: string(name='message', example='"success"'),
  requestId?: string(name='requestId', example='C38F034D-7F36-531C-95AC-0C752F80E840'),
  success?: boolean(name='success', example='True'),
}

model PodcastTaskResultQueryResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: PodcastTaskResultQueryResponseBody(name='body'),
}

/**
 * @summary ai播客生成任务结果查询
 *
 * @param request PodcastTaskResultQueryRequest
 * @param headers map
 * @param runtime runtime options for this request RuntimeOptions
 * @return PodcastTaskResultQueryResponse
 */
async function podcastTaskResultQueryWithOptions(request: PodcastTaskResultQueryRequest, headers: map[string]string, runtime: $RuntimeOptions): PodcastTaskResultQueryResponse {
  request.validate();
  var body : map[string]any = {};
  if (!$isNull(request.taskId)) {
    body['taskId'] = request.taskId;
  }
  if (!$isNull(request.workspaceId)) {
    body['workspaceId'] = request.workspaceId;
  }

  var req = new OpenApiUtil.OpenApiRequest{ 
    headers = headers,
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApiUtil.Params{
    action = 'PodcastTaskResultQuery',
    version = '2025-02-28',
    protocol = 'HTTPS',
    pathname = `/podcast/task`,
    method = 'POST',
    authType = 'AK',
    style = 'ROA',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  if ($isNull(@signatureVersion) || @signatureVersion != 'v4') {
    return callApi(params, req, runtime);
  } else {
    return execute(params, req, runtime);
  }
}

/**
 * @summary ai播客生成任务结果查询
 *
 * @param request PodcastTaskResultQueryRequest
 * @return PodcastTaskResultQueryResponse
 */
async function podcastTaskResultQuery(request: PodcastTaskResultQueryRequest): PodcastTaskResultQueryResponse {
  var runtime = new $RuntimeOptions{};
  var headers : map[string]string = {};
  return podcastTaskResultQueryWithOptions(request, headers, runtime);
}

model PodcastTaskSubmitRequest {
  counts?: int32(name='counts', example='2'),
  fileUrls?: [ string ](name='fileUrls'),
  text?: string(name='text'),
  topic?: string(name='topic'),
  voices?: [ string ](name='voices'),
  workspaceId?: string(name='workspaceId', description='This parameter is required.', example='llm-ep8ba0dr6seiddxx'),
}

model PodcastTaskSubmitShrinkRequest {
  counts?: int32(name='counts', example='2'),
  fileUrlsShrink?: string(name='fileUrls'),
  text?: string(name='text'),
  topic?: string(name='topic'),
  voicesShrink?: string(name='voices'),
  workspaceId?: string(name='workspaceId', description='This parameter is required.', example='llm-ep8ba0dr6seiddxx'),
}

model PodcastTaskSubmitResponseBody = {
  code?: string(name='code', example='"success"'),
  data?: {
    taskId?: string(name='taskId', example='63c4e0eaab3b4c0db208ecafa990e8d1'),
    taskStatus?: string(name='taskStatus', example='SUCCEEDED'),
  }(name='data'),
  httpStatusCode?: string(name='httpStatusCode', example='200'),
  message?: string(name='message', example='"success"'),
  requestId?: string(name='requestId', example='9CE5B91A-6E6B-55FB-A1AF-037DF01C84B3'),
  success?: boolean(name='success', example='True'),
}

model PodcastTaskSubmitResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: PodcastTaskSubmitResponseBody(name='body'),
}

/**
 * @summary ai播客生成任务提交
 *
 * @param tmpReq PodcastTaskSubmitRequest
 * @param headers map
 * @param runtime runtime options for this request RuntimeOptions
 * @return PodcastTaskSubmitResponse
 */
async function podcastTaskSubmitWithOptions(tmpReq: PodcastTaskSubmitRequest, headers: map[string]string, runtime: $RuntimeOptions): PodcastTaskSubmitResponse {
  tmpReq.validate();
  var request = new PodcastTaskSubmitShrinkRequest{};
  OpenApiUtil.convert(tmpReq, request);
  if (!$isNull(tmpReq.fileUrls)) {
    request.fileUrlsShrink = OpenApiUtil.arrayToStringWithSpecifiedStyle(tmpReq.fileUrls, 'fileUrls', 'json');
  }
  if (!$isNull(tmpReq.voices)) {
    request.voicesShrink = OpenApiUtil.arrayToStringWithSpecifiedStyle(tmpReq.voices, 'voices', 'json');
  }
  var body : map[string]any = {};
  if (!$isNull(request.counts)) {
    body['counts'] = request.counts;
  }
  if (!$isNull(request.fileUrlsShrink)) {
    body['fileUrls'] = request.fileUrlsShrink;
  }
  if (!$isNull(request.text)) {
    body['text'] = request.text;
  }
  if (!$isNull(request.topic)) {
    body['topic'] = request.topic;
  }
  if (!$isNull(request.voicesShrink)) {
    body['voices'] = request.voicesShrink;
  }
  if (!$isNull(request.workspaceId)) {
    body['workspaceId'] = request.workspaceId;
  }

  var req = new OpenApiUtil.OpenApiRequest{ 
    headers = headers,
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApiUtil.Params{
    action = 'PodcastTaskSubmit',
    version = '2025-02-28',
    protocol = 'HTTPS',
    pathname = `/podcast/task/submit`,
    method = 'POST',
    authType = 'AK',
    style = 'ROA',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  if ($isNull(@signatureVersion) || @signatureVersion != 'v4') {
    return callApi(params, req, runtime);
  } else {
    return execute(params, req, runtime);
  }
}

/**
 * @summary ai播客生成任务提交
 *
 * @param request PodcastTaskSubmitRequest
 * @return PodcastTaskSubmitResponse
 */
async function podcastTaskSubmit(request: PodcastTaskSubmitRequest): PodcastTaskSubmitResponse {
  var runtime = new $RuntimeOptions{};
  var headers : map[string]string = {};
  return podcastTaskSubmitWithOptions(request, headers, runtime);
}

